using System;
using System.Collections.Generic;

namespace SqlInjectionScanner.Models
{
    /// <summary>
    /// 扫描结果模型
    /// </summary>
    public class ScanResult
    {
        /// <summary>
        /// 数据库名称
        /// </summary>
        public string DatabaseName { get; set; } = string.Empty;

        /// <summary>
        /// 表名
        /// </summary>
        public string TableName { get; set; } = string.Empty;

        /// <summary>
        /// 列名
        /// </summary>
        public string ColumnName { get; set; } = string.Empty;

        /// <summary>
        /// 数据类型
        /// </summary>
        public string DataType { get; set; } = string.Empty;

        /// <summary>
        /// 主键值（如果有）
        /// </summary>
        public string? PrimaryKeyValue { get; set; }

        /// <summary>
        /// 主键列名
        /// </summary>
        public string? PrimaryKeyColumn { get; set; }

        /// <summary>
        /// 可疑值
        /// </summary>
        public string SuspiciousValue { get; set; } = string.Empty;

        /// <summary>
        /// 匹配的注入模式
        /// </summary>
        public InjectionPattern MatchedPattern { get; set; } = null!;

        /// <summary>
        /// 风险等级
        /// </summary>
        public RiskLevel RiskLevel => MatchedPattern.RiskLevel;

        /// <summary>
        /// 注入类型
        /// </summary>
        public InjectionType InjectionType => MatchedPattern.InjectionType;

        /// <summary>
        /// 扫描时间
        /// </summary>
        public DateTime ScanTime { get; set; } = DateTime.Now;

        /// <summary>
        /// 修复建议
        /// </summary>
        public string RemediationAdvice { get; set; } = string.Empty;
    }

    /// <summary>
    /// 扫描统计信息
    /// </summary>
    public class ScanStatistics
    {
        /// <summary>
        /// 扫描的数据库数量
        /// </summary>
        public int DatabaseCount { get; set; }

        /// <summary>
        /// 扫描的表数量
        /// </summary>
        public int TableCount { get; set; }

        /// <summary>
        /// 扫描的列数量
        /// </summary>
        public int ColumnCount { get; set; }

        /// <summary>
        /// 扫描的记录数量
        /// </summary>
        public long RecordCount { get; set; }

        /// <summary>
        /// 发现的可疑记录数量
        /// </summary>
        public int SuspiciousRecordCount { get; set; }

        /// <summary>
        /// 按风险等级统计的问题数量
        /// </summary>
        public Dictionary<RiskLevel, int> IssuesByRiskLevel { get; set; } = new Dictionary<RiskLevel, int>();

        /// <summary>
        /// 按注入类型统计的问题数量
        /// </summary>
        public Dictionary<InjectionType, int> IssuesByType { get; set; } = new Dictionary<InjectionType, int>();

        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime StartTime { get; set; }

        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime EndTime { get; set; }

        /// <summary>
        /// 扫描持续时间
        /// </summary>
        public TimeSpan Duration => EndTime - StartTime;
    }
}